package leetcode_core.leetcode_6;

import org.junit.Test;

import java.util.Arrays;
import java.util.Map;

/**
 * 功能描述
 *
 * @author: 张庭杰
 * @date: 2023年02月02日 13:59
 */
public class NextPermutation {
    public void nextPermutation(int[] nums) {
        if(nums == null || nums.length == 0 || nums.length == 1){
            return;
        }
        int n = nums.length;
        int i = n-2;int j = n-1;
        while(i>=0 && nums[i] >= nums[j]){
            i--;
            j--;
        }
        if(i >= 0){
            j = n-1;
            while(j > i && nums[i] >= nums[j]){
                j--;
            }
            int temp = nums[j];
            nums[j] = nums[i];
            nums[i] = temp;
        }
        i = i+1;j = n-1;
        while(i<j){
            int temp = nums[i];
            nums[i] = nums[j];
            nums[j] = temp;
            i++;j--;
        }
    }

    @Test
    public void test(){
        nextPermutation(new int[]{3,2,1});
    }

}
